#include"heapsort.h"

void swap(hpdatatype* p1, hpdatatype* p2)
{
	hpdatatype tmp = *p1;
	*p1 = *p2;
	*p2 = tmp;
}



void ajustdown(hpdatatype* a, int n, int parent)
{
	int child = 2 * parent + 1;
	while (child < n)
	{
		if (child + 1 < n && a[child] < a[child + 1])
		{
			child++;
		}
		if (a[parent] < a[child])
		{
			swap(&a[parent], &a[child]);
			parent = child;
			child = 2 * parent + 1;
		}
		else
		{
			break;
		}
	}
}
